package com.ruoyi.fund.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.fund.domain.DmsFundRecord;
import com.ruoyi.fund.service.IDmsFundRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资金记录Controller
 * 
 * @author liuchuanfa
 * @date 2024-03-06
 */
@RestController
@RequestMapping("/whole/fundRecord")
public class DmsFundRecordController extends BaseController
{
    @Autowired
    private IDmsFundRecordService dmsFundRecordService;

    /**
     * 查询资金记录列表
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsFundRecord dmsFundRecord)
    {
        startPage();
        List<DmsFundRecord> list = dmsFundRecordService.selectDmsFundRecordList(dmsFundRecord);
        return getDataTable(list);
    }

    /**
     * 导出资金记录列表
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:export')")
    @Log(title = "资金记录 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsFundRecord dmsFundRecord)
    {
        List<DmsFundRecord> list = dmsFundRecordService.selectDmsFundRecordList(dmsFundRecord);
        ExcelUtil<DmsFundRecord> util = new ExcelUtil<DmsFundRecord>(DmsFundRecord.class);
        util.exportExcel(response, list, "资金记录数据");
    }

    /**
     * 获取资金记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsFundRecordService.selectDmsFundRecordById(id));
    }

    /**
     * 新增资金记录
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:add')")
    @Log(title = "资金记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsFundRecord dmsFundRecord)
    {
        return toAjax(dmsFundRecordService.insertDmsFundRecord(dmsFundRecord));
    }

    /**
     * 修改资金记录
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:edit')")
    @Log(title = "资金记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsFundRecord dmsFundRecord)
    {
        return toAjax(dmsFundRecordService.updateDmsFundRecord(dmsFundRecord));
    }

    /**
     * 删除资金记录
     */
    @PreAuthorize("@ss.hasPermi('whole:fund:remove')")
    @Log(title = "资金记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsFundRecordService.deleteDmsFundRecordByIds(ids));
    }
}
